package com.topcoder.srm484;

public class PuyoPuyo {
    static final long MOD = 1000000007;
 
    public int theCount(int L, int N) {
        if (N % L != 0)
            return 0;
        int am = N / L;
        long[][] ways = new long[am + 2][N + L + 1];
        ways[0][0] = 1;
        for (int done = 0; done <= am; ++done)
            for (int pos = 0; pos <= N; ++pos)
                if (ways[done][pos] != 0) {
                    if (pos == done * L) {
                        ways[done + 1][pos + 1] = (ways[done + 1][pos + 1] + 4 * ways[done][pos]) % MOD;
                    } else {
                        ways[done + 1][pos + 1] = (ways[done + 1][pos + 1] + 3 * ways[done][pos]) % MOD;
                        ways[done][pos + 1] = (ways[done][pos + 1] + ways[done][pos]) % MOD;
                    }
                }
        return (int) ways[am][N];
    }
}
